package controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import pojo.User;

@Controller
public class TestController {
    //提交的域名称和处理方法的参数名一致
    //http://localhost:8080/hello1?name=kuangshen
    @RequestMapping("/hello1")
    public String Test1(String name) {
        System.out.println(name);
        return "hello";
    }

    //提交的域名称和处理方法的参数名不一致
    //@RequestParam("username") : username提交的域的名称 .
    //http://localhost:8080/hello2?username=kuangshen
    @RequestMapping("/hello2")
    public String Test2(@RequestParam("username") String name) {
        System.out.println(name);
        return "hello";
    }

    //提交的是一个对象
    //http://localhost:8080/user?name=kuangshen&id=1&age=15
    @RequestMapping("/user")
    public String Test3(User user) {
        System.out.println(user);
        return "hello";
    }


//    数据显示到前端
    // http://localhost:8080/hello3?username=kuangshen
    @RequestMapping("/hello3")
    public String Test4(@RequestParam("username") String name, ModelMap model) {
        //封装要显示到视图中的数据
        //相当于req.setAttribute("name",name);
        model.addAttribute("name", name);
        System.out.println(name);
        return "hello";
    }


}
